/*
 * @File    :   users.js
 * @Time    :   2024/03/24 16:42:33
 * @Author  :   chakcy
 * @Email   :   947105045@qq.com
 * @description   :   用户表操作
 */

const { pool, DataTable } = require('../../../common')
const path = require('path')
const { basePath } = require('../../../config')

async function userOptions() {
    const db = await pool.acquire().catch(err => {
        console.error(err)
    })
    const users = new DataTable(path.join(basePath, './common/mapper/users'), db)
    // 根据id查询用户
    const result = await users.execute('getUserById', [
        { name: 'id', value: 1 }
    ]).catch(err => {
        console.error(err)
    })
    console.log("getUserById", result)

    // 插入用户
    await users.execute('insertUser', [
        { name: 'name', value: 'chakcy' },
        { name: 'email', value: '947105045@qq.com' },
        { name: 'password', value: '123456' }
    ]).catch(err => {
        console.error(err)
    })

    // 查询所有用户
    const allUsers = await users.execute('getAllUsers', []).catch(err => {
        console.error(err)
    })
    console.log("getAllUsers", allUsers)
}

module.exports = {
    userOptions
}